﻿using System;
using System.Collections.Generic;
using System.Data;
using PPI.Entities.Distribution;
using PPIDataAccess.Distribution;

namespace PPI.ServiceLogic.Distribution
{
    public class LDistributionPole
    {
        public static Int32 Insert(EMeter meter, Int32 poleId, string connectionString)
        {
            return DMeter.Insert(meter, poleId, connectionString);
        }

        public static Int32 Insert(ETransformer transformer, Int32 poleId, string connectionString)
        {
            return DTransformer.Insert(transformer, poleId, connectionString);
        }

        public static Int32 Insert(ESectionalizer sectionalizer, Int32 poleId, string connectionString)
        {
            return DSectionalizer.Insert(sectionalizer, poleId, connectionString);
        }

        public static Int32 Insert(ERecloser recloser, Int32 poleId, string connectionString)
        {
            return DRecloser.Insert(recloser, poleId, connectionString);
        }

        public static void Update(EMeter meter, Int32 poleId, string connectionString)
        {
            DMeter.Update(meter, poleId, connectionString);
        }

        public static void Delete (Int32 poleId, string connectionString)
        {
            DPole.Delete(poleId, connectionString);
        }

        public static void DeleteImages(int[] poleImagesIds, string connectionString)
        {
            DPole.DeleteImages(poleImagesIds, connectionString);
        }

        public static DataSet SelectWithoutImages(string connectionString)
        {
            return DMeter.SelectWithoutImages(connectionString);
        }
        
        public static Int32 Insert(ENote note, Int32 poleId, string connectionString)
        {
            return DPole.Insert(note, poleId, connectionString);
        }

        public static void Update(List<ENote> notes, Int32 poleId, string connectionString)
        {
            DPole.Update(notes, poleId, connectionString);
        }

        public static Int32 InsertMeterNote(ENote note, Int32 meterId, string connectionString)
        {
            return DMeterNote.Insert(note, meterId, connectionString);
        }

        public static void InsertTransformerNote(EDistributionLookUp note, Int32 transformerId, string connectionString)
        {
            DTransformer.InsertNote(transformerId, note.Id, connectionString);
        }

        public static void InsertSectionalizerNote(EDistributionLookUp note, Int32 sectionalizerId, string connectionString)
        {
            DSectionalizer.InsertNote(sectionalizerId, note.Id, connectionString);
        }

        public static void InsertRecloserNote(EDistributionLookUp note, Int32 recloserId, string connectionString)
        {
            DRecloser.InsertNote(recloserId, note.Id, connectionString);
        }

        public static Int32 Insert(EDistributionPole pole, string connectionString)
        {
            return DPole.Insert(pole, connectionString);
        }

        public static Int32 Update(EDistributionPole pole, string connectionString)
        {
            return DPole.Update(pole, connectionString);
        }

        public static Int32 Insert(EDistributionPoleImage image, Int32 poleId, string connectionString)
        {
            Int32 idImage = DPole.Insert(image, poleId, connectionString);
            string fileName = poleId + "_" + idImage + ".jpg";

            DPole.ImageUpdate(idImage, fileName, connectionString);

            return idImage;
        }

        public static void MeterImageUpdate(EDistributionPoleImage image, Int32 meterId, string connectionString)
        {
            DPole.MeterImageUpdate(image, meterId, connectionString);
        }

        public static Int32 TransformerImageInsert(EDistributionPoleImage image, Int32 transformerId, string connectionString)
        {
            Int32 idImage = DPole.TransformerImageInsert(image, transformerId, connectionString);
            string fileName = transformerId + "_" + idImage + ".jpg";

            DPole.TransformerImageUpdate(idImage, fileName, connectionString);

            return idImage;
        }

        public static Int32 SectionalizerImageInsert(EDistributionPoleImage image, Int32 sectionalizerId, string connectionString)
        {
            Int32 idImage = DPole.SectionalizerImageInsert(image, sectionalizerId, connectionString);
            string fileName = sectionalizerId + "_" + idImage + ".jpg";

            DPole.SectionalizerImageUpdate(idImage, fileName, connectionString);

            return idImage;
        }

        public static Int32 RecloserImageInsert(EDistributionPoleImage image, Int32 recloserId, string connectionString)
        {
            Int32 idImage = DPole.RecloserImageInsert(image, recloserId, connectionString);
            string fileName = recloserId + "_" + idImage + ".jpg";

            DPole.RecloserImageUpdate(idImage, fileName, connectionString);

            return idImage;
        }

        public static Int32 Insert(EDistributionInspectionResult inspectionResult, Int32 idPole, string connectionString)
        {
            return DInspectionResult.Insert(inspectionResult, idPole, connectionString);
        }

        public static void Update(EDistributionInspectionResult inspectionResult, Int32 idPole, string connectionString)
        {
            DInspectionResult.Update(inspectionResult, idPole, connectionString);
        }

        public static void DeleteMeter(Int32 idMeter, string connectionString)
        {
            DMeter.Delete(idMeter, connectionString);
        }

        public static void SelectLookUps(string connectionString)
        {
            DDistributionLookup.SelectAll(connectionString);
        }
        
    }
}
